<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-row :gutter="5">
        <el-col :span="4">
          <el-form-item label="成果类型" prop="achievementType">
            <el-select v-model="queryParams.achievementType" placeholder="请选择成果类型" clearable @change="handleTypeChange">
              <el-option
                v-for="dict in dict.type.sci_out_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item :label="getDynamicLabelByQuery()" prop="achievementName">
            <el-input
              v-model="queryParams.achievementName"
              placeholder="请输入名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="所属方向" prop="deptId">
            <el-select
              v-model="queryParams.deptId"
              placeholder="请选择所属方向"
              @change="handleQueryDeptChange"
              clearable
            >
              <el-option
                v-for="dept in deptList"
                :key="dept.deptId"
                :label="dept.deptName"
                :value="dept.deptId"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">


        <el-form-item label="所属项目" prop="userId">
          <el-select
            v-model="queryParams.projectId"
            placeholder="请选择所属项目"
            clearable
          >
            <el-option
              v-for="project in projectList"
              :key="project.projectId"
              :label="project.projectName"
              :value="project.projectId"
            />
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="4" v-for="filter in dynamicFilters" :key="filter.prop">
        <el-form-item  :label="filter.label" :prop="filter.prop">
          <el-input
            v-if="filter.type === 'input'"
            v-model="queryParams[filter.prop]"
            :placeholder="`请输入${filter.label}`"
            clearable
          />
          <el-select
            v-if="filter.type === 'select'"
            v-model="queryParams[filter.prop]"
            :placeholder="`请选择${filter.label}`"
            clearable
          >
            <el-option
              v-for="option in filter.options"
              :key="option.value"
              :label="option.label"
              :value="option.value"
            />
          </el-select>
          <el-date-picker
            v-if="filter.type === 'date'"
            v-model="queryParams[filter.prop]"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            :placeholder="`请选择${filter.label}`"
            clearable
          />
        </el-form-item>
      </el-col>
      <el-col :span="4" :offset="20" style="text-align: right;">
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>

    </el-row>
    </el-form>


    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:achievements:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:achievements:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:achievements:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:achievements:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- <el-table v-loading="loading" :data="outputList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="成果ID" align="center" prop="achievementId" />
      <el-table-column label="成果类型" align="center" prop="achievementType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sci_out_type" :value="scope.row.achievementType"/>
        </template>
      </el-table-column>
      <el-table-column label="名称" align="center" prop="achievementName" />
      <el-table-column label="成果详细信息" align="center" prop="achievementDetails" />
      <el-table-column label="所属部门ID" align="center" prop="deptId" />
      <el-table-column label="所属用户ID" align="center" prop="userId" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="关联项目Id" align="center" prop="projectId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:output:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:output:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table> -->
    <el-table v-loading="loading" :data="outputListWithProjectName" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="成果类型" align="center" prop="achievementType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sci_out_type" :value="scope.row.achievementType"/>
        </template>
      </el-table-column>
      <el-table-column :label="getDynamicLabelByQuery()" align="center" prop="achievementName" />
      <el-table-column v-for="column in dynamicColumns" :key="column.prop" :label="column.label" align="center" :prop="column.prop">
        <template slot-scope="scope">
          {{ scope.row.achievementDetails[column.prop] }}
        </template>
      </el-table-column>
      <el-table-column label="所属方向" align="center" prop="deptName" />
      <!-- <el-table-column label="所属人员" align="center" prop="nickName" /> -->

      <el-table-column label="所属项目" align="center" prop="projectName" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:achievements:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:achievements:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改科研成果录入对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" size="medium" label-width="110px">
        <el-row :gutter="15">
          <el-col :span="6">
            <el-form-item label="成果类型" prop="achievementType">
              <el-select v-model="form.achievementType" placeholder="请选择成果类型" clearable :style="{width: '100%'}">
                <el-option
                  v-for="dict in dict.type.sci_out_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="getDynamicLabel()" prop="achievementName">
              <el-input v-model="form.achievementName" :placeholder="getDynamicPlaceholder()" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所属方向" prop="deptId">
              <el-select v-model="form.deptId" placeholder="请选择所属方向" clearable :style="{width: '100%'}">
                <el-option
                  v-for="dept in deptList"
                  :key="dept.deptId"
                  :label="dept.deptName"
                  :value="dept.deptId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所属项目" prop="projectId">
              <el-select v-model="form.projectId" placeholder="请选择所属项目" clearable :style="{width: '100%'}">
                <!-- <el-option v-for="(item, index) in projectIdOptions" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option> -->

                <el-option
                  v-for="project in projectList"
                  :key="project.projectId"
                  :label="project.projectName"
                  :value="project.projectId"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 专利 -->
        <el-row v-if="form.achievementType === '专利'" :gutter="15">
          <el-col :span="6">
            <el-form-item label="专利申请号" prop="patentNumber">
              <el-input v-model="form.patentNumber" placeholder="请选择专利申请号" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="发明人" prop="inventors">
              <el-input v-model="form.inventors" placeholder="请输入发明人" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="申请人" prop="applicant">
              <el-input v-model="form.applicant" placeholder="请输入申请人" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="申请状态" prop="applicationStatus">
              <el-select v-model="form.applicationStatus" placeholder="请输入申请状态" clearable :style="{width: '100%'}">
                <el-option
                  v-for="dict in dict.type.sci_ach_appl_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="申请日期" prop="applicationDate">
              <el-date-picker v-model="form.applicationDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请输入申请日期" clearable></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="公开日期" prop="patentPublicationDate">
              <el-date-picker v-model="form.publicationDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请输入公开日期" clearable></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="公开号" prop="publicationNumber">
              <el-input v-model="form.publicationNumber" placeholder="请输入公开号" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 论文 -->
        <el-row v-if="form.achievementType === '论文'" :gutter="15">
          <el-col :span="6">
            <el-form-item label="按次序作者" prop="authors">
              <el-input v-model="form.authors" placeholder="请选择按次序作者" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="出版单位" prop="publisher">
              <el-input v-model="form.publisher" placeholder="请输入出版单位" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="期刊名称" prop="journalName">
              <el-input v-model="form.journalName" placeholder="请输入期刊名称" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="统一刊号" prop="issn">
              <el-input v-model="form.issn" placeholder="请输入统一刊号" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="发表日期" prop="paperPublicationDate">
              <el-date-picker v-model="form.paperPublicationDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请输入发表日期" clearable></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="论文类型" prop="paperType">
              <el-select v-model="form.paperType" placeholder="请输入论文类型" clearable :style="{width: '100%'}">
                <el-option
                  v-for="dict in dict.type.sci_paper_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否核心期刊" prop="isCoreJournal">
              <el-select v-model="form.isCoreJournal" placeholder="请输入是否核心期刊" clearable :style="{width: '100%'}">
                <el-option v-for="(item, index) in isCoreJournalOptions" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="期刊类型" prop="coreJournalType">
              <el-select v-model="form.coreJournalType" placeholder="请输入期刊类型" clearable :style="{width: '100%'}">
                <el-option
                  v-for="dict in dict.type.sci_journal_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 软著 -->
        <el-row v-if="form.achievementType === '软著'" :gutter="15">
          <el-col :span="6">
            <el-form-item label="软主权人" prop="copyrightOwner">
              <el-input v-model="form.copyrightOwner" placeholder="请选择软主权人" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="开发完成日期" prop="developmentDate">
              <el-date-picker v-model="form.developmentDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请输入开发完成日期" clearable></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="首次发表日期" prop="firstPublicationDate">
              <el-date-picker v-model="form.firstPublicationDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请输入首次发表日期" clearable></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="权利取得方式" prop="rightsAcquisitionMethod">
              <el-select v-model="form.rightsAcquisitionMethod" placeholder="请输入权利取得方式" clearable :style="{width: '100%'}">
                <el-option
                  v-for="dict in dict.type.sci_rights_method"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="登记号" prop="registrationNumber">
              <el-input v-model="form.registrationNumber" placeholder="请选择登记号" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 报告 -->
        <el-row v-if="form.achievementType === '科研报告'" :gutter="15">
          <el-col :span="6">
            <el-form-item label="报告编号" prop="reportNumber">
              <el-input v-model="form.reportNumber" placeholder="请选择报告编号" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="按次序作者" prop="authors">
              <el-input v-model="form.authors" placeholder="请选择按次序作者" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="报告日期" prop="reportDate">
              <el-date-picker v-model="form.reportDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请选择报告日期" clearable></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="研究领域" prop="researchField">
              <el-input v-model="form.researchField" placeholder="请选择研究领域" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否涉密" prop="isConfidential">
              <el-select v-model="form.isConfidential" placeholder="请选择是否涉密" clearable :style="{width: '100%'}">
                <el-option v-for="(item, index) in isConfidentialOptions" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 项目 -->
        <el-row v-if="form.achievementType === '项目'" :gutter="15">
          <el-col :span="6">
            <el-form-item label="项目来源" prop="projectSource">
              <el-select v-model="form.projectSource" placeholder="请选择项目来源" clearable :style="{width: '100%'}">
                <el-option v-for="(item, index) in projectSourceOptions" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="技术领域" prop="technologyField">
              <el-input v-model="form.technologyField" placeholder="请选择技术领域" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="承担单位" prop="affiliation">
              <el-input v-model="form.affiliation" placeholder="请选择承担单位" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="负责人" prop="principal">
              <el-input v-model="form.principal" placeholder="请选择负责人" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目地点" prop="location">
              <el-input v-model="form.location" placeholder="请选择项目地点" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 获奖 -->

        <el-row v-if="form.achievementType === '获奖类'" :gutter="15">
          <el-col :span="6">
            <el-form-item label="获奖级别" prop="awardLevel">
              <el-select v-model="form.awardLevel" placeholder="请选择下拉选择获奖级别" clearable
                :style="{width: '100%'}">
                <el-option
                  v-for="dict in dict.type.sci_award_level"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="获奖等级" prop="awardRank">
              <el-select v-model="form.awardRank" placeholder="请选择下拉选择获奖等级" clearable
                :style="{width: '100%'}">
                <el-option
                  v-for="dict in dict.type.sci_award_rank"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="获奖人员" prop="awardRecipients">
              <el-input v-model="form.awardRecipients" placeholder="请输入获奖人员" clearable
                prefix-icon='el-icon-user' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="获奖时间" prop="awardDate">
              <el-date-picker v-model="form.awardDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                :style="{width: '100%'}" placeholder="请输入获奖时间" clearable></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="获奖作品" prop="awardName">
              <el-input v-model="form.awardName" placeholder="请输入获奖作品" clearable
                prefix-icon='el-icon-s-cooperation' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="颁奖机构" prop="awardingInstitution">
              <el-input v-model="form.awardingInstitution" placeholder="请输入颁奖机构" clearable
                prefix-icon='el-icon-s-cooperation' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 标准 -->
        <el-row v-if="form.achievementType === '标准'" :gutter="15">
          <el-col :span="6">
            <el-form-item label="标准体系编号" prop="sysNum">
              <el-input v-model="form.sysNum" placeholder="请输入标准体系编号" clearable
                prefix-icon='el-icon-picture-outline-round' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="标准号" prop="stdCode">
              <el-input v-model="form.stdCode" placeholder="请输入标准号" clearable
                prefix-icon='el-icon-circle-plus-outline' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="标准级别" prop="stdLevel">
              <el-select v-model="form.stdLevel" placeholder="请输入标准级别" clearable :style="{width: '100%'}">
                <el-option
                  v-for="dict in dict.type.sci_std_level"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="标准类别" prop="stdCategory">
              <el-select v-model="form.stdCategory" placeholder="请输入标准类别" clearable
                :style="{width: '100%'}">
                <el-option
                  v-for="dict in dict.type.sci_std_category"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="实施日期" prop="implDate">
              <el-date-picker v-model="form.implDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                :style="{width: '100%'}" placeholder="请输入实施日期" clearable></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row v-if="form.achievementType === '学术交流'" :gutter="15">
          <el-col :span="6">
            <el-form-item label="参加人员" prop="participants">
              <el-input v-model="form.participants" placeholder="请输入参加人员" clearable
                prefix-icon='el-icon-user' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="会议地点" prop="location">
              <el-input v-model="form.location" placeholder="请输入会议地点" clearable
                prefix-icon='el-icon-s-help' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="举办单位" prop="organizer">
              <el-input v-model="form.organizer" placeholder="请输入举办单位" clearable
                prefix-icon='el-icon-s-check' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="会议日期" prop="meetingDate">
              <el-date-picker v-model="form.meetingDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                :style="{width: '100%'}" placeholder="请输入会议日期" clearable></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="会议形式" prop="meetingFormat">
              <el-select v-model="form.meetingFormat" placeholder="请输入会议形式" clearable
                :style="{width: '100%'}">
                <el-option
                  v-for="dict in dict.type.sci_meeting_format"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="会议标准类型" prop="meetStdType">
              <el-select v-model="form.meetStdType" placeholder="请输入会议标准类型" clearable :style="{width: '100%'}">
                <el-option
                  v-for="dict in dict.type.sci_meet_std_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row v-if="form.achievementType === '科技成果'" :gutter="15">
          <el-col :span="6">
            <el-form-item label="完成人" prop="completer">
              <el-input v-model="form.completer" placeholder="请输入完成人" clearable prefix-icon='el-icon-user'
                :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="会议地点" prop="completionCompany">
              <el-input v-model="form.completionCompany" placeholder="请输入会议地点" clearable
                prefix-icon='el-icon-s-help' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="鉴定时间" prop="evaluationDate">
              <el-date-picker v-model="form.evaluationDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                :style="{width: '100%'}" placeholder="请输入鉴定时间" clearable></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="主持人" prop="host">
              <el-input v-model="form.host" placeholder="请输入主持人" clearable
                prefix-icon='el-icon-user-solid' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="参与人" prop="participants">
              <el-input v-model="form.participants" placeholder="请输入参与人" clearable
                prefix-icon='el-icon-s-custom' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="鉴定单位" prop="evaluatingCompany">
              <el-input v-model="form.evaluatingCompany" placeholder="请输入鉴定单位" clearable
                prefix-icon='el-icon-s-home' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row v-if="form.achievementType === '成果转化合同'" :gutter="15">
          <el-col :span="6">
            <el-form-item label="委托方" prop="customer">
              <el-input v-model="form.customer" placeholder="请输入委托方" clearable prefix-icon='el-icon-user'
                :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="合同签订时间" prop="field145">
              <el-date-picker v-model="form.field145" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                :style="{width: '100%'}" placeholder="请输入合同签订时间" clearable></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="期限" prop="duration">
              <el-input v-model="form.duration" placeholder="请输入期限" clearable
                prefix-icon='el-icon-reading' :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="合同经费" prop="contractFunds">
              <el-input v-model="form.contractFunds" placeholder="请输入合同经费" clearable
                prefix-icon='el-icon-money' :style="{width: '100%'}">
                <template slot="append">万元</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>


        <el-col :span="24">
          <el-form-item label="相关文档资料" prop="fileUrl">
            <file-upload v-model="form.fileUrl"/>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="submitForm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAchievements, getAchievements, delAchievements, addAchievements, updateAchievements } from "@/api/sci/achievements";
import { listDept } from '@/api/system/dept';
import { listUserByDeptId } from '@/api/system/user';
import { listProject } from '@/api/sci/project';

export default {
  name: "Output",
  dicts: ['sci_out_type','sci_ach_appl_status','sci_meet_std_type','sci_meeting_format','sci_std_category','sci_std_level'
    ,'sci_award_rank','sci_award_level','sci_rights_method','sci_journal_type','sci_paper_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 科研成果录入表格数据
      outputList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        achievementType: null,
        achievementName: null,
        achievementDetails: null,
        attachmentUrl: null,
        deptId: null,
        userId: null,
        projectId: null
      },
      deptList: [],
      userList: [],
      projectList: [],
      queryUserList: [],
      dynamicColumns:[],
      dynamicFilters:[],


      filterConfig: {

          专利: [
            { label: '专利申请号', prop: 'patentNumber', type: 'input' },
            { label: '发明人', prop: 'inventors', type: 'input' },
            { label: '申请人', prop: 'applicant', type: 'input' },
            { label: '申请状态', prop: 'applicationStatus', type: 'select', options:  [] },
            { label: '申请日期', prop: 'applicationDate', type: 'date' },
            { label: '公开日期', prop: 'publicationDate', type: 'date' },
            { label: '公开号', prop: 'publicationNumber', type: 'input' }
          ],
          论文: [
            { label: '按次序作者', prop: 'authors', type: 'input' },
            { label: '出版单位', prop: 'publisher', type: 'input' },
            { label: '期刊名称', prop: 'journalName', type: 'input' },
            { label: '统一刊号', prop: 'issn', type: 'input' },
            { label: '发表日期', prop: 'publicationDate', type: 'date' },
            { label: '论文类型', prop: 'paperType', type: 'select', options: [] },
            { label: '是否核心期刊', prop: 'isCoreJournal', type: 'select', options:  [] },
            { label: '期刊类型', prop: 'coreJournalType', type: 'select', options:  [] }
          ],
          软著: [
            { label: '软主权人', prop: 'copyrightOwner', type: 'input' },
            { label: '开发完成日期', prop: 'developmentDate', type: 'date' },
            { label: '首次发表日期', prop: 'firstPublicationDate', type: 'date' },
            { label: '权利取得方式', prop: 'rightsAcquisitionMethod', type: 'select', options:  [] },
            { label: '登记号', prop: 'registrationNumber', type: 'input' }
          ],
          科研报告: [
            { label: '报告编号', prop: 'reportNumber', type: 'input' },
            { label: '按次序作者', prop: 'authors', type: 'input' },
            { label: '报告日期', prop: 'reportDate', type: 'date' },
            { label: '研究领域', prop: 'researchField', type: 'input' },
            { label: '是否涉密', prop: 'isConfidential', type: 'select', options:  [] }
          ],
          项目: [
            { label: '项目来源', prop: 'projectSource', type: 'select', options:  [] },
            { label: '技术领域', prop: 'technologyField', type: 'input' },
            { label: '承担单位', prop: 'affiliation', type: 'input' },
            { label: '负责人', prop: 'principal', type: 'input' },
            { label: '项目地点', prop: 'location', type: 'input' }
          ],

          获奖类: [
            { label: '获奖级别', prop: 'awardLevel', type: 'select', options: [] },
            { label: '获奖等级', prop: 'awardRank', type: 'select', options: [] },
            { label: '获奖人员', prop: 'awardRecipients', type: 'input' },
            { label: '获奖时间', prop: 'awardDate', type: 'date' },
            { label: '获奖作品', prop: 'awardName', type: 'input' },
            { label: '颁奖机构', prop: 'awardingInstitution', type: 'input' }
          ],
          标准: [
            { label: '标准体系编号', prop: 'sysNum', type: 'input' },
            { label: '标准号', prop: 'stdCode', type: 'input' },
            { label: '标准级别', prop: 'stdLevel', type: 'select', options: [] },
            { label: '标准类别', prop: 'stdCategory', type: 'select', options: [] },
            { label: '实施日期', prop: 'implDate', type: 'date' }
          ],
          学术交流: [
            { label: '参加人员', prop: 'participants', type: 'input' },
            { label: '会议地点', prop: 'location', type: 'input' },
            { label: '举办单位', prop: 'organizer', type: 'input' },
            { label: '会议日期', prop: 'meetingDate', type: 'date' },
            { label: '会议形式', prop: 'meetingFormat', type: 'select', options: [] },
            { label: '标准类型', prop: 'meetStdType', type: 'select', options: [] }
          ],
          科技成果: [
            { label: '完成人', prop: 'completer', type: 'input' },
            { label: '完成单位', prop: 'completionCompany', type: 'input' },
            { label: '鉴定时间', prop: 'evaluationDate', type: 'date' },
            { label: '主持人', prop: 'host', type: 'input' },
            { label: '参与人', prop: 'participants', type: 'input' },
            { label: '鉴定单位', prop: 'evaluatingCompany', type: 'input' }
          ],
          成果转化合同: [
            { label: '委托方', prop: 'customer', type: 'input' },
            { label: '合同签订时间', prop: 'contractSigningDate', type: 'date' },
            { label: '期限', prop: 'duration', type: 'input' },
            { label: '合同经费', prop: 'contractFunds', type: 'input' }
          ]
      },
      tableConfig: {
        专利: [
          { label: '专利申请号', prop: 'patentNumber' },
          { label: '发明人', prop: 'inventors' },
          { label: '申请人', prop: 'applicant' },
          { label: '申请状态', prop: 'applicationStatus' },
          { label: '申请日期', prop: 'applicationDate' },
          { label: '公开日期', prop: 'publicationDate' },
          { label: '公开号', prop: 'publicationNumber' }
        ],
        论文: [
          { label: '按次序作者', prop: 'authors' },
          { label: '出版单位', prop: 'publisher' },
          { label: '期刊名称', prop: 'journalName' },
          { label: '统一刊号', prop: 'issn' },
          { label: '发表日期', prop: 'publicationDate' },
          { label: '论文类型', prop: 'paperType' },
          { label: '是否核心期刊', prop: 'isCoreJournal' },
          { label: '期刊类型', prop: 'coreJournalType' }
        ],
        软著: [
          { label: '软主权人', prop: 'copyrightOwner' },
          { label: '开发完成日期', prop: 'developmentDate' },
          { label: '首次发表日期', prop: 'firstPublicationDate' },
          { label: '权利取得方式', prop: 'rightsAcquisitionMethod' },
          { label: '登记号', prop: 'registrationNumber' }
        ],
        科研报告: [
          { label: '报告编号', prop: 'reportNumber' },
          { label: '按次序作者', prop: 'authors' },
          { label: '报告日期', prop: 'reportDate' },
          { label: '研究领域', prop: 'researchField' },
          { label: '是否涉密', prop: 'isConfidential' }
        ],
        项目: [
          { label: '项目来源', prop: 'projectSource' },
          { label: '技术领域', prop: 'technologyField' },
          { label: '承担单位', prop: 'affiliation' },
          { label: '负责人', prop: 'principal' },
          { label: '项目地点', prop: 'location' }
        ],
        获奖类: [
          { label: '获奖级别', prop: 'awardLevel' },
          { label: '获奖等级', prop: 'awardRank' },
          { label: '获奖人员', prop: 'awardRecipients' },
          { label: '获奖时间', prop: 'awardDate' },
          { label: '获奖作品', prop: 'awardName' },
          { label: '颁奖机构', prop: 'awardingInstitution' }
        ],
        标准: [
          { label: '标准体系编号', prop: 'sysNum' },
          { label: '标准号', prop: 'stdCode' },
          { label: '标准级别', prop: 'stdLevel' },
          { label: '标准类别', prop: 'stdCategory' },
          { label: '实施日期', prop: 'implDate' }
        ],
        学术交流: [
          { label: '参加人员', prop: 'participants' },
          { label: '会议地点', prop: 'location' },
          { label: '举办单位', prop: 'organizer' },
          { label: '会议日期', prop: 'meetingDate' },
          { label: '会议形式', prop: 'meetingFormat' },
          { label: '标准类型', prop: 'meetStdType' }
        ],
        科技成果: [
          { label: '完成人', prop: 'completer' },
          { label: '完成单位', prop: 'completionCompany' },
          { label: '鉴定时间', prop: 'evaluationDate' },
          { label: '主持人', prop: 'host' },
          { label: '参与人', prop: 'participants' },
          { label: '鉴定单位', prop: 'evaluatingCompany' }
        ],
        成果转化合同: [
          { label: '委托方', prop: 'customer' },
          { label: '合同签订时间', prop: 'contractSigningDate' },
          { label: '期限', prop: 'duration' },
          { label: '合同经费', prop: 'contractFunds' }
        ]
      },
      // 科研成果录入表单数据
      // 表单参数
      form: {
        achievementType: '',
        achievementName: '',
        deptId: '',
        projectId: '',
        patentNumber: '',
        inventors: '',
        applicant: '',
        applicationStatus: '',
        applicationDate: '',
        patentPublicationDate: '',
        paperPublicationDate: '',
        publicationNumber: '',
        authors: '',
        publisher: '',
        journalName: '',
        issn: '',
        paperType: '',
        isCoreJournal: '',
        coreJournalType: '',
        copyrightOwner: '',
        developmentDate: '',
        firstPublicationDate: '',
        rightsAcquisitionMethod: '',
        registrationNumber: '',
        reportNumber: '',
        reportDate: '',
        researchField: '',
        isConfidential: '',
        projectSource: '',
        technologyField: '',
        affiliation: '',
        principal: '',
        location: ''
      },
      // 表单校验
      rules: {
        achievementType: [{
          required: true,
          message: '请选择成果类型',
          trigger: 'change'
        }],
        achievementName: [{
          required: true,
          message: '请输入成果名称',
          trigger: 'blur'
        }],
        deptId: [{
          required: true,
          message: '请选择所属方向',
          trigger: 'change'
        }],
        projectId: [],
        patentNumber: [{
          required: true,
          message: '请选择专利申请号',
          trigger: 'blur'
        }],
        inventors: [{
          required: true,
          message: '请输入发明人',
          trigger: 'blur'
        }],
        applicant: [{
          required: true,
          message: '请输入申请人',
          trigger: 'blur'
        }],
        applicationStatus: [{
          required: true,
          message: '请输入申请状态',
          trigger: 'change'
        }],
        applicationDate: [{
          required: true,
          message: '请输入申请日期',
          trigger: 'change'
        }],
        patentPublicationDate: [],
        publicationNumber: [],
        authors: [{
          required: true,
          message: '请选择按次序作者',
          trigger: 'blur'
        }],
        publisher: [{
          required: true,
          message: '请输入出版单位',
          trigger: 'blur'
        }],
        journalName: [{
          required: true,
          message: '请输入期刊名称',
          trigger: 'blur'
        }],
        issn: [{
          required: true,
          message: '请输入统一刊号',
          trigger: 'blur'
        }],
        paperPublicationDate: [{
          required: true,
          message: '请输入发表日期',
          trigger: 'change'
        }],
        paperType: [],
        isCoreJournal: [{
          required: true,
          message: '请输入是否核心期刊',
          trigger: 'change'
        }],
        coreJournalType: [{
          required: true,
          message: '请输入期刊类型',
          trigger: 'change'
        }],
        copyrightOwner: [{
          required: true,
          message: '请选择软著权人',
          trigger: 'blur'
        }],
        developmentDate: [{
          required: true,
          message: '请输入开发完成日期',
          trigger: 'change'
        }],
        firstPublicationDate: [{
          required: true,
          message: '请输入首次发表日期',
          trigger: 'change'
        }],
        rightsAcquisitionMethod: [{
          required: true,
          message: '请输入权利取得方式',
          trigger: 'change'
        }],
        registrationNumber: [{
          required: true,
          message: '请选择登记号',
          trigger: 'blur'
        }],
        reportNumber: [{
          required: true,
          message: '请选择报告编号',
          trigger: 'blur'
        }],
        authors: [{
          required: true,
          message: '请选择按次序作者',
          trigger: 'blur'
        }],
        reportDate: [{
          required: true,
          message: '请选择报告日期',
          trigger: 'change'
        }],
        researchField: [{
          required: true,
          message: '请选择研究领域',
          trigger: 'blur'
        }],
        isConfidential: [{
          required: true,
          message: '请选择是否涉密',
          trigger: 'change'
        }],
        projectSource: [{
          required: true,
          message: '请选择项目来源',
          trigger: 'change'
        }],
        technologyField: [{
          required: true,
          message: '请选择技术领域',
          trigger: 'blur'
        }],
        affiliation: [{
          required: true,
          message: '请选择承担单位',
          trigger: 'blur'
        }],
        principal: [{
          required: true,
          message: '请选择负责人',
          trigger: 'blur'
        }],
        location: [{
          required: true,
          message: '请选择项目地点',
          trigger: 'blur'
        }],

        awardLevel: [{
          required: true,
          message: '请选择下拉选择获奖级别',
          trigger: 'change'
        }],
        awardRank: [{
          required: true,
          message: '请选择下拉选择获奖等级',
          trigger: 'change'
        }],
        awardRecipients: [{
          required: true,
          message: '请输入获奖人员',
          trigger: 'blur'
        }],
        awardDate: [{
          required: true,
          message: '请输入获奖时间',
          trigger: 'change'
        }],
        awardName: [{
          required: true,
          message: '请输入获奖作品',
          trigger: 'blur'
        }],
        awardingInstitution: [{
          required: true,
          message: '请输入颁奖机构',
          trigger: 'blur'
        }],
        sysNum: [{
          required: true,
          message: '请输入标准体系编号',
          trigger: 'blur'
        }],
        stdCode: [{
          required: true,
          message: '请输入标准号',
          trigger: 'blur'
        }],
        stdLevel: [{
          required: true,
          message: '请输入标准级别',
          trigger: 'change'
        }],
        stdCategory: [{
          required: true,
          message: '请输入标准类别',
          trigger: 'change'
        }],
        implDate: [{
          required: true,
          message: '请输入实施日期',
          trigger: 'change'
        }],
        participants: [{
          required: true,
          message: '请输入参加人员',
          trigger: 'blur'
        }],
        location: [{
          required: true,
          message: '请输入会议地点',
          trigger: 'blur'
        }],
        organizer: [{
          required: true,
          message: '请输入举办单位',
          trigger: 'blur'
        }],
        meetingType: [{
          required: true,
          message: '请输入会议类型',
          trigger: 'change'
        }],
        meetingFormat: [{
          required: true,
          message: '请输入会议形式',
          trigger: 'change'
        }],
        meetStdType: [{
          required: true,
          message: '请输入标注类型',
          trigger: 'change'
        }],
        completer: [{
          required: true,
          message: '请输入完成人',
          trigger: 'blur'
        }],
        completionCompany: [{
          required: true,
          message: '请输入会议地点',
          trigger: 'blur'
        }],
        evaluationDate: [{
          required: true,
          message: '请输入鉴定时间',
          trigger: 'change'
        }],
        host: [{
          required: true,
          message: '请输入主持人',
          trigger: 'blur'
        }],
        participants: [{
          required: true,
          message: '请输入参与人',
          trigger: 'blur'
        }],
        evaluatingCompany: [{
          required: true,
          message: '请输入鉴定单位',
          trigger: 'blur'
        }],
        customer: [{
          required: true,
          message: '请输入委托方',
          trigger: 'blur'
        }],
        field145: [{
          required: true,
          message: '请输入合同签订时间',
          trigger: 'change'
        }],
        duration: [{
          required: true,
          message: '请输入期限',
          trigger: 'blur'
        }],
        contractFunds: [{
          required: true,
          message: '请输入合同经费',
          trigger: 'blur'
        }],
      },

      isCoreJournalOptions: [{
        "label": "是",
        "value": "是"
      }, {
        "label": "否",
        "value": "否"
      }],

      isConfidentialOptions: [{
        "label": "是",
        "value": "是"
      }, {
        "label": "否",
        "value": "否"
      }],
    };
  },
  created() {
    this.getList();
    this.getDeptList();
    this.getProjectList();
  },
  computed: {
    outputListWithProjectName() {
      return this.outputList.map(achievement => {
        const project = this.projectList.find(project => project.projectId === achievement.projectId);
        return {
          ...achievement,
          projectName: project ? project.projectName : ''
        };
      });
    }
  },
  methods: {
    /** 查询科研成果录入列表 */
    getList() {
      this.loading = true;
      listAchievements(this.queryParams).then(response => {
        this.outputList = response.rows.map(row => ({
          ...row,
          achievementDetails: JSON.parse(row.achievementDetails || '{}')
        }));
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        achievementId: null,
        achievementType: null,
        achievementName: null,
        achievementDetails: null,
        attachmentUrl: null,
        isDeleted: null,
        approvedBy: null,
        approvedAt: null,
        approvalStatus: null,
        deptId: null,
        userId: null,
        log: null,
        createdBy: null,
        updatedBy: null,
        createdTime: null,
        updatedTime: null,
        remark: null,
        projectId: null
      };
      this.resetForm("form");
    },
    handleTypeChange() {
      if (this.dict && this.dict.type) {
        this.dynamicFilters = this.filterConfig[this.queryParams.achievementType] || [];
        this.dynamicColumns = this.tableConfig[this.queryParams.achievementType] || [];
         // 为 options 绑定值
        this.dynamicFilters.forEach(filter => {
          switch (filter.prop) {
              case 'applicationStatus':
                filter.options = this.dict.type.sci_ach_appl_status || [];
                break;
              case 'paperType':
                filter.options = this.dict.type.sci_paper_type || [];
                break;
              case 'isCoreJournal':
                filter.options = this.isCoreJournalOptions || [];
                break;
              case 'coreJournalType':
                filter.options = this.dict.type.sci_journal_type || [];
                break;
              case 'rightsAcquisitionMethod':
                filter.options = this.dict.type.sci_rights_method || [];
                break;
              case 'awardLevel':
                filter.options = this.dict.type.sci_award_level || [];
                break;
              case 'awardRank':
                filter.options = this.dict.type.sci_award_rank || [];
                break;
              case 'stdLevel':
                filter.options = this.dict.type.sci_std_level || [];
                break;
              case 'stdCategory':
                filter.options = this.dict.type.sci_std_category || [];
                break;
              case 'meetingFormat':
                filter.options = this.dict.type.sci_meeting_format || [];
                break;
              case 'meetStdType':
                filter.options = this.dict.type.sci_meet_std_type || [];
                break;
              case 'isConfidential':
                filter.options = this.isConfidentialOptions || [];
                break;
              case 'projectSource':
                filter.options = this.projectSourceOptions || [];
                break;
              default:
                filter.options = [];
            }
        });
        this.handleQuery();
      } else {
        console.warn('dict or dict.type is not defined');
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.achievementId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加科研成果";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const achievementId = row.achievementId || this.ids
      getAchievements(achievementId).then(response => {
        const data = response.data;
        this.form = {
          ...data,
          ...JSON.parse(data.achievementDetails || '{}')
        };
        this.open = true;
        this.title = "修改科研成果信息";
      });
    },
    getDynamicLabel() {
      switch (this.form.achievementType) {
        case '专利':
          return '专利名称';
        case '论文':
          return '论文名称';
        case '软著':
          return '软著名称';
        case '科研报告':
          return '报告名称';
        case '项目':
          return '项目名称';
        case '获奖类':
          return '获奖名称';
        case '标准':
          return '标准名称';
        case '学术交流':
          return '会议名称';
        case '科技成果':
          return '科技成果名称';
        case '成果转化合同':
          return '合同名称';
        default:
          return '名称';
      }
    },

    getDynamicLabelByQuery() {
      switch (this.queryParams.achievementType) {
        case '专利':
          return '专利名称';
        case '论文':
          return '论文名称';
        case '软著':
          return '软著名称';
        case '科研报告':
          return '报告名称';
        case '项目':
          return '项目名称';
        case '获奖类':
          return '获奖名称';
        case '标准':
          return '标准名称';
        case '学术交流':
          return '会议名称';
        case '科技成果':
          return '科技成果名称';
        case '成果转化合同':
          return '合同名称';
        default:
          return '名称';
      }
    },

    getDynamicPlaceholder() {
      switch (this.form.achievementType) {
        case '专利':
          return '请输入专利名称';
        case '论文':
          return '请输入论文名称';
        case '软著':
          return '请输入软著名称';
        case '科研报告':
          return '请输入报告名称';
        case '项目':
          return '请输入项目名称';
        case '获奖类':
          return '请输入获奖名称';
        case '标准':
         return '请输入标准名称';
        case '学术交流':
          return '请输入会议名称';
        case '科技成果':
          return '请输入科技成果名称';
        case '成果转化合同':
          return '请输入合同名称';
        default:
          return '请输入名称';
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 构建 achievementDetails 对象
        let achievementDetails = {};
        switch (this.form.achievementType) {
          case '专利':
            achievementDetails = {
              patentNumber: this.form.patentNumber,
              inventors: this.form.inventors,
              applicant: this.form.applicant,
              applicationStatus: this.form.applicationStatus,
              applicationDate: this.form.applicationDate,
              publicationDate: this.form.patentPublicationDate,
              publicationNumber: this.form.publicationNumber
            };
            break;
          case '论文':
            achievementDetails = {
              authors: this.form.authors,
              publisher: this.form.publisher,
              journalName: this.form.journalName,
              issn: this.form.issn,
              publicationDate: this.form.paperPublicationDate,
              paperType: this.form.paperType,
              isCoreJournal: this.form.isCoreJournal,
              coreJournalType: this.form.coreJournalType
            };
            break;
          case '软著':
            achievementDetails = {
              copyrightOwner: this.form.copyrightOwner,
              developmentDate: this.form.developmentDate,
              firstPublicationDate: this.form.firstPublicationDate,
              rightsAcquisitionMethod: this.form.rightsAcquisitionMethod,
              registrationNumber: this.form.registrationNumber
            };
            break;
          case '科研报告':
            achievementDetails = {
              reportNumber: this.form.reportNumber,
              authors: this.form.authors,
              reportDate: this.form.reportDate,
              researchField: this.form.researchField,
              isConfidential: this.form.isConfidential
            };
            break;
          case '项目':
            achievementDetails = {
              projectSource: this.form.projectSource,
              technologyField: this.form.technologyField,
              affiliation: this.form.affiliation,
              principal: this.form.principal,
              location: this.form.location
            };
            break;
          case '获奖类':
            achievementDetails = {
              awardLevel: this.form.awardLevel,
              awardRank: this.form.awardRank,
              awardRecipients: this.form.awardRecipients,
              awardDate: this.form.awardDate,
              awardName: this.form.awardName,
              awardingInstitution: this.form.awardingInstitution
            };
            break;
          case '标准':
            achievementDetails = {
              sysNum: this.form.sysNum,
              stdCode: this.form.stdCode,
              stdLevel: this.form.stdLevel,
              stdCategory: this.form.stdCategory,
              implDate: this.form.implDate
            };
            break;
          case '学术交流':
            achievementDetails = {
              participants: this.form.participants,
              location: this.form.location,
              organizer: this.form.organizer,
              meetingDate: this.form.meetingDate,
              meetingFormat: this.form.meetingFormat,
              meetStdType: this.form.meetStdType
            };
            break;
          case '科技成果':
            achievementDetails = {
              completer: this.form.completer,
              completionCompany: this.form.completionCompany,
              evaluationDate: this.form.evaluationDate,
              host: this.form.host,
              participants: this.form.participants,
              evaluatingCompany: this.form.evaluatingCompany
            };
            break;
          case '成果转化合同':
            achievementDetails = {
              customer: this.form.customer,
              contractSigningDate: this.form.contractSigningDate,
              duration: this.form.duration,
              contractFunds: this.form.contractFunds
            };
            break;

          default:
            achievementDetails = {};
        }

        // 将 achievementDetails 赋值给 this.form.achievementDetails
        this.form.achievementDetails = JSON.stringify(achievementDetails);

          if (this.form.achievementId != null) {
            updateAchievements(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAchievements(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const achievementIds = row.achievementId || this.ids;
      this.$modal.confirm('是否确认删除科研成果录入编号为"' + achievementIds + '"的数据项？').then(function() {
        return delAchievements(achievementIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/output/export', {
        ...this.queryParams
      }, `output_${new Date().getTime()}.xlsx`)
    },
    getDeptList() {
      listDept().then(response => {
        this.deptList = response.data;
      });
    },
    handleDeptChange(deptId) {
      this.form.userId = null; // 置空用户ID
      if (deptId) {
        listUserByDeptId(deptId).then(response => {
          this.userList = response.data;
        });
      } else {
        this.userList = [];
      }
    },
    handleQueryDeptChange(deptId) {
      this.queryParams.userId = null; // 置空用户ID
      if (deptId) {
        listUserByDeptId(deptId).then(response => {
          this.queryUserList = response.data;
        });
      } else {
        this.queryUserList = [];
      }
    },
    getProjectList() {
      listProject().then(response => {
        this.projectList = response.rows;
      });
    }
  }
};
</script>
